
<template>
  <div class="wrap" style="padding: 15px">
    <el-row>
      <el-form :inline="true" :model="queryParams" class="demo-form-inline">
        <el-form-item label="方案名称">
          <el-input
            v-model="queryParams.schemeName"
            placeholder="方案名称"
            clearable
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row>
      <el-button type="primary" style="margin-bottom: 15px" @click="add"
        >新增</el-button
      >
    </el-row>

    <el-table :data="tableData" style="width: 100%" stripe v-loading="loading">
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column label="方案名称" prop="schemeName"></el-table-column>
      <el-table-column label="是否使用" prop="status">
        <template slot-scope="scope">
          {{ scope.row.status == 0 ? "不可用" : "可用" }}
        </template>
      </el-table-column>
      <el-table-column label="上次修改时间" prop="modifyTime"></el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="edit(scope.row)"
            >编辑</el-button
          >
          <el-button type="primary" size="small" @click="openSetting(scope.row)"
            >方案设置</el-button
          >
          <el-button type="danger" size="small" @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="text-align: right">
      <el-pagination
        @size-change="getData"
        @current-change="getData"
        :current-page.sync="queryParams.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <add ref="add" />
    <el-dialog
      title="定价方案"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false"
      custom-class="dialog-my"
    >
      <el-form v-loading="loadingForm">
        <el-form-item label="请选择定价方案">
          <el-select v-model="regulationName" placeholder="请选择活动区域">
            <el-option
              v-for="item in list"
              :key="item.id"
              :label="item.regulationName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="sumbit" :loading="loadingForm"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Add from './add.vue'
import { schemePageList, schemeDel, setPageList, addRegulation } from '@/config/api'
export default {
  components: {
    Add
  },
  data () {
    return {

      tableData: [],
      total: 0,
      loading: false,
      loadingForm: false,
      dialogFormVisible: false,
      regulationName: "",
      schemeId: "",
      list: [],
      queryParams: {
        page: 1,
        pageSize: 10,
        schemeName: ""
      }

    };
  },

  created () {
    this.getData()
  },
  methods: {
    // 新增
    add () {
      this.$refs.add.addShow()
    },
    edit (record) {
      this.$refs.add.editShow(record)
    },

    to_setting () {
      console.log(9)
      this.$router.push('/sports/setting')
    },
    getData () {
      schemePageList(this.queryParams).then(res => {
        this.tableData = res.data.result.list
        this.regulationName = ""
        this.total = res.data.result.total
      })
    },
    getRegulation (regionId) {
      setPageList({ regionId }).then(res => {
        this.list = res.data.result.list
      })
    },
    del (id) {
      this.$confirm('此操作将删除该场区, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        schemeDel({ id }).then(res => {
          if (res.data.status == 200) {
            this.getData()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    openSetting (record) {
      this.getRegulation(record.regionId)
      this.dialogFormVisible = true
      this.schemeId = record.id
      this.regulationName = record.regulationKey
    },
    sumbit () {
      this.loadingForm = true
      addRegulation({ regulationSetId: this.regulationName, schemeId: this.schemeId }).then(res => {
        this.dialogFormVisible = false
        this.$message({
          message: '操作成功',
          type: 'success'
        });
        this.getData()
        this.loadingForm = false
      })
    }
  },
};
</script>
